package com.qf.service.impl;

import com.qf.dao.AccountDao;
import com.qf.pojo.Account;
import com.qf.service.AccountService;

import org.springframework.transaction.annotation.Transactional;


/**
 * @ClassName AccountServiceImpl
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/1 17:09
 * @Version 1.0
 **/
public class AccountServiceImpl implements AccountService {
    private AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao){
        this.accountDao=accountDao;
    }

    @Override
    @Transactional //事务注解
    public void transfer(String soureName, String targetName, double money) {
        Account accountByName = accountDao.findAccountByName(soureName);
        Account account = accountDao.findAccountByName(targetName);
        accountByName.setMoney(accountByName.getMoney()-money);
        account.setMoney(account.getMoney()+money);
        accountDao.updateAccount(accountByName);
       // int i=1/0;
        accountDao.updateAccount(account);


    }
}
